package com.jboa.action;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.jboa.model.Module;
import com.jboa.service.ModuleService;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;


public class ModuleAction extends ActionSupport{
	private Module module;
	private List<Module> moduleList;
	private ModuleService moduleService;
	
	public Module getModule() {
		return module;
	}

	public void setModule(Module module) {
		this.module = module;
	}

	public List<Module> getModuleList() {
		return moduleList;
	}

	public void setModuleList(List<Module> moduleList) {
		this.moduleList = moduleList;
	}

	public void setModuleService(ModuleService moduleService) {
		this.moduleService = moduleService;
	}
	
	public String findModule() {
		HttpSession hs = ServletActionContext.getRequest().getSession();		
		List<Module> mlist = 
			moduleService.findModule((List<Integer>) hs.getAttribute("role"));
		Set mset = new HashSet(mlist);
		hs.setAttribute("mlist", mset);
		return Action.SUCCESS;
	}
	
	// ����operateModule����ķ���
	public String operateModule() {
		moduleList = moduleService.operateModule();
		return SUCCESS;
	}
	// ����newModule����ķ���
	public String newModule() {
		moduleService.newModule(module);
		return SUCCESS;
	}
	// ����findSingleModule����ķ���
	public String findSingleModule() {
		module = moduleService.findSingleModule(module.getId());
		return Action.SUCCESS;
	}
	// ����modifyModule����ķ���
	public String modifyModule() {
		moduleService.modifyModule(module);
		return Action.SUCCESS;
	}
	// ����removeModule����ķ���
	public String removeModule() {
		moduleService.removeModule(module);
		return Action.SUCCESS;
	}
	
}
